package context.util;

public class Timer
{
    
    private static final double SEC_PER_NANO = 1.0e-9;
    
    
    private long mTime;
    
    
    public Timer()
    {
        this.mTime = 0L;
    }
    
    
    public void start()
    {
        this.mTime = System.nanoTime();
    }
    
    public void clear()
    {
        this.mTime = 0L;
    }
    
    
    /** Gets the time passed and resets the timer. */
    public double delta()
    {
        // Compute the time passed:
        long curTime = System.nanoTime();
        long deltaL = curTime - this.mTime;
        double deltaSec = deltaL * Timer.SEC_PER_NANO;
        // Reset the timer:
        this.mTime = curTime;
        // Return the time passed:
        return deltaSec;
    }
    
}
